fix(pnpm): rewrite pnpm commands with global flags before the subcommand - #3275
Open
breisnerlopez wants to merge 1 commit into
Open
fix(pnpm): rewrite pnpm commands with global flags before the subcommand#3275breisnerlopez wants to merge 1 commit into
breisnerlopez wants to merge 1 commit into
Conversation
The hook rewriter matched pnpm via a subcommand allowlist anchored right after `pnpm ` (`^pnpm\s+(install|list|...)`), so flag-first monorepo forms were never rewritten and streamed raw: pnpm run build -> rtk pnpm run build (matched) pnpm -r install -> (not rewritten) pnpm --filter @app list -> (not rewritten) pnpm -w install -> (not rewritten) Add `strip_pnpm_global_opts` (mirror of the existing `strip_git_global_opts`) that strips a fixed set of pnpm global options (`-r`/`--recursive`, `-w`/`--workspace-root`, `--filter`/`-F`) for CLASSIFICATION only. The rewrite step still operates on the original text via `strip_word_prefix`, so an unknown flag or a flag-first form with no matching rewrite prefix is a safe no-op — never a malformed rewrite. `rtk pnpm` now accepts `-r`/`-w` globally and forwards them. The flags are forwarded after the subcommand (`pnpm install -r`), matching the established `--filter` handling. This is behavior-preserving: they are root-level pnpm options accepted in either position (verified against pnpm 9.15.4; `pnpm <flag> <sub>` and `pnpm <sub> <flag>` produce identical output and install scope for `-r`, `-w`, and `--filter`). Adds 16 tests: flag-first rewrite forms, no-regression on bare forms, and false-positive guards (unknown flag not stripped, filter without subcommand, recursive-lint safe no-op).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The hook rewriter matches pnpm via a subcommand allowlist anchored right after
pnpm(^pnpm\s+(exec|i|install|list|ls|outdated|run|run-script)), with no stripping of pnpm global options. So flag-first monorepo forms are never rewritten and stream raw:pnpm run buildpnpm -r installpnpm --filter @app listpnpm -w installFix
Add
strip_pnpm_global_opts— a direct mirror of the existingstrip_git_global_opts(#163) — that strips a fixed set of pnpm global options (-r/--recursive,-w/--workspace-root,--filter/-F) for classification only, in the same spot git is normalized inclassify_command.The rewrite step still operates on the original command text via
strip_word_prefix, so:pnpm -x build) is not stripped → no match → no rewrite;pnpm -r lint) is a safe no-op, never a malformed rewrite.rtk pnpmnow accepts-r/-was global flags and forwards them. They are appended after the subcommand (pnpm install -r), matching the established--filterhandling — behavior-preserving, since these are root-level pnpm options accepted in either position (verified against pnpm 9.15.4:pnpm install --helplists them, andpnpm <flag> <sub>vspnpm <sub> <flag>produce identical output and install scope for-r,-w,--filter).Tests
16 new tests: flag-first rewrite forms (
-r,--filter,-F,--filter=,-w, combos), no-regression on bare forms (pnpm install,pnpm run build,pnpm buildstillNone), false-positive guards (unknown flag not stripped,--filterwithout subcommand, recursive-lint safe no-op), CLI parse tests, and the merge ordering.cargo fmt --check,cargo clippy --all-targets, andcargo testall clean.Note
The glued short filter form
-F@app(no space) is not stripped; it falls back to the existing safe passthrough (no scope change), consistent with pre-existing behavior.